<template>
 <div>
    <div id="wangeditor">
        <div ref="editorElem" style="text-align:left" ></div>
    </div>  
 </div>
</template>

<script>
import E from 'wangeditor'
// import * as constant from "@/libs/constant";

 export default {
   data () {
     return {
         editor:'',
         content:''
     }
   },
   components: {
       E
   },
   props:['catchData','editorContent'],
   methods: {
       initEditor(){
            let that = this
            this.content = this.editorContent
            this.editor = new E(this.$refs.editorElem)     
            this.editor.customConfig.onchange = (html) => {
                // this.content = html
                that.catchData(html)  
                // this.$emit('contentChange',html)
            }
            this.editor.customConfig.menus = [
                'head',  // 标题
                'bold',  // 粗体
                'list',  // 列表
                'justify',  // 对齐方式
                'image',  // 插入图片
                'undo',  // 撤销
            ]
            this.editor.customConfig.debug = true
            this.editor.customConfig.uploadImgMaxLength = 1
            this.editor.customConfig.pasteFilterStyle = false
            this.editor.customConfig.uploadImgServer = 'http://59.110.234.118:9100/uploadImgs/upload'
            this.editor.customConfig.uploadFileName = 'file'
            this.editor.customConfig.uploadImgHooks = {
                before: function (xhr, editor, files) {},
                success: function (xhr, editor, result) {},
                fail: function (xhr, editor, result) {},
                customInsert: function (insertImg, result, editor) {
                    if(result.code == 1){
                        insertImg(result.data)
                    }
                }
            }
            this.editor.create()
            this.editor.txt.html(this.editorContent)
       },
       insertHTML(html){
            this.editor.cmd.do('insertHTML', html)
       }
   },
   mounted() {
       this.initEditor()
   },
 }
</script>

<style>

 
</style>
